import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {
  CompletedQuery,
  CompletedType,
  ExperimentQuery,
  MarkVo,
  MarkingRequest,
  SysUserCourseFile,
} from "./types";
/**
 * 课程分页列表
 *
 * @param queryParams
 */
export function getExperimentPageOf(
  queryParams: ExperimentQuery
): AxiosPromise<PageResult<SysUserCourseFile[]>> {
  return request({
    url: "/api/v1/course/experiment/student/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 课程分页列表
 *
 * @param queryParams
 */
export function getCompletedPage(
  queryParams: CompletedQuery
): AxiosPromise<PageResult<CompletedType[]>> {
  return request({
    url: "/api/v1/course/experiment/completed/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 下载文件
 *
 * @param queryParams
 */
export function downloadReportsExperiment(
  experimentId: number,
  userIds?: string
): AxiosPromise<string> {
  return request({
    url: "/api/v1/file/downloadReports",
    method: "get",
    params: {
      experimentId,
      userIds,
    },
    responseType: "blob",
  });
}

/**
 * 查询人数
 *
 * @param queryParams
 */
export function numberQuery(experimentId: number) {
  return request({
    url: "/api/v1/course/experiment/eachStatus",
    method: "get",
    params: {
      experimentId,
    },
  });
}

/**
 * 查询规则
 *
 * @param queryParams
 */
export function rulesQuery(experimentId: number) {
  return request({
    url: "/api/v1/course/experiment/rule",
    method: "get",
    params: {
      experimentId,
    },
  });
}

/**
 * 批改成绩
 *
 * @param queryParams
 */
export function markingofresults(
  userCourseFileId: number,
  queryParams: MarkingRequest
) {
  return request({
    url: "/api/v1/course/experiment/mark/" + userCourseFileId,
    method: "post",
    data: queryParams,
  });
}

/**
 * 重新批改成绩
 */
export function againmarkingofresults(
  userCourseFileId: number
): AxiosPromise<MarkVo> {
  return request({
    url: "/api/v1/course/experiment/echo/" + userCourseFileId,
    method: "get",
  });
}

/**
 * 导出用户
 *
 * @param experimentId
 * @returns
 */
export function exportexperiment(experimentId: number, fileName?: string) {
  return request({
    url: "/api/v1/course/experiment/export",
    method: "get",
    params: { experimentId, fileName },
    responseType: "arraybuffer",
  });
}
/**
 * 添加课程
 *
 * @param queryParams
 *
 */
export function getExpInfoApi(experimentId: number) {
  return request({
    url: "/api/v1/course/experiment/correct/detail",
    method: "get",
    params: {
      experimentId,
    },
  });
}

/**
 * 获取班级信息
 *
 * @param queryParams
 *
 */
export function getClassInfo(experimentId: number) {
  return request({
    url: "/api/v1/course/experiment/class",
    method: "get",
    params: {
      experimentId,
    },
  });
}

/**
 * 驳回
 *
 * @param queryParams
 *
 */
export function reportdiSmissed(userCourseFileId: number) {
  return request({
    url: "/api/v1/course/experiment/rejected/" + userCourseFileId,
    method: "get",
  });
}

/**
 * 连续批改作业
 *
 * @param queryParams
 *
 */
export function continuousCorrect(
  experimentId: number
): AxiosPromise<SysUserCourseFile> {
  return request({
    url: "/api/v1/course/experiment/continuously",
    method: "get",
    params: {
      experimentId,
    },
  });
}

/**
 * 立刻执行查重任务
 *
 * @param data
 * @returns
 */
export function duplicateExperiment({
  courseId,
  experimentId,
}: {
  courseId: number;
  experimentId: number;
}) {
  return request({
    url: "/api/v1/course/experiment/duplicate",
    method: "post",
    params: {
      courseId,
      experimentId,
    },
  });
}
